import java.util.*;
class StudentSort implements Comparable {
    double d=0;
    String s="";
    StudentSort (double d) {
        this.d=d;
    }
    StudentSort (String s) {
        this.s=s;
    }
    public int compareTo(Object b) {
        StudentSort st=(StudentSort)b;
        if((this.d-st.d)==0)
            return -1;
        else
            return (int)((this.d-st.d)*1000);
    }
}
class Student {
    String name=null;
    double math,english,computer,total,aver;
    Student(String s, double m, double e, double f, double a,double b) {
        name=s;
        math=m;
        english=e;
        computer=f;
        total=a;
        aver=b;
    }
}
public class StudentTest {
    public static void main(String args[]) {
        TreeMap<StudentSort, Student> treemap = new TreeMap<StudentSort, Student>();
        String str[] = {"20165229赵凯杰", "20165230田坤烨", "20165231王杨鸿永", "20165232何彦达", "20165233张雨昕"};
        double math[] = {89, 45, 78, 76, 70};
        double english[] = {67, 68, 69, 70, 71};
        double computer[] = {76, 66, 30, 65, 80};
        double total[] = new double[5];
        double aver[] = new double[5];
        Student student[] = new Student[5];
        for (int k = 0; k < student.length; k++) {
            total[k] = math[k] + english[k] + computer[k];
            aver[k] = total[k] / 3;
        }
        for (int k = 0; k < student.length; k++) {
            student[k] = new Student(str[k], math[k], english[k], computer[k], total[k], aver[k]);
        }
        StudentSort key[] = new StudentSort[5];
        for (int k = 0; k < key.length; k++) {
            key[k] = new StudentSort(student[k].total);
        }
        for (int k = 0; k < student.length; k++) {
            treemap.put(key[k], student[k]);
        }
        int number = treemap.size();
        System.out.println("有" + number + "个对象,按总成绩排序:");
        Collection<Student> collection = treemap.values();
        Iterator<Student> iter = collection.iterator();
        while (iter.hasNext()) {
            Student stu = iter.next();
            System.out.println("姓名 " + stu.name + " 总成绩 " + stu.total);
        }
    }
}
